package com.jstyle.jclife.daoManager;

import com.jstyle.jclife.dao.NotifyDataDao;
import com.jstyle.jclife.model.NotifyData;
import com.jstyle.jclife.utils.DbManager;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * Created by Administrator on 2017/4/10.
 */

public class NotifyDataDaoManager {

    /**插入数据，存在就更新，不存在插入；insertOrReplace适合手动添加id
     * save是判断id是否存在，适合有设置自增长id的实体
     * @param notifyData
     * @param
     */
    public static void insertNotifyData(NotifyData notifyData){
        DbManager.getInstance().getDaoSession().getNotifyDataDao().insert(notifyData);
    }
    public static void updateNotifyData(NotifyData notifyData){
        DbManager.getInstance().getDaoSession().getNotifyDataDao().update(notifyData);
    }
    public static NotifyData getNotifyData(long id){
        NotifyDataDao notifyDataDao=DbManager.getInstance().getDaoSession().getNotifyDataDao();
        QueryBuilder<NotifyData> builder = notifyDataDao.queryBuilder();
        builder.where(NotifyDataDao.Properties.Id.eq(id));
        NotifyData notifyData=builder.unique();
        if(notifyData==null){
            notifyData = new NotifyData();
            notifyData.setId(id);
           insertNotifyData(notifyData);
        }
        return notifyData;
    }
    public static NotifyData getNotifyDataByUid(String uid){
        NotifyDataDao notifyDataDao=DbManager.getInstance().getDaoSession().getNotifyDataDao();
        QueryBuilder<NotifyData> builder = notifyDataDao.queryBuilder();
        builder.where(NotifyDataDao.Properties.Name.eq(uid));
        return builder.unique();
    }
    public static List<NotifyData> getNotifyData(){
        NotifyDataDao notifyDataDao=DbManager.getInstance().getDaoSession().getNotifyDataDao();
        QueryBuilder<NotifyData> builder = notifyDataDao.queryBuilder();
        return builder.list();
    }

}
